package cn.ygh.bbo.system;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * spring 容器初始化后调用
 * @author
 *
 */
@Component
public class ApplicationInit implements ApplicationListener<ContextRefreshedEvent> {
	/**日志实例*/
	private final Log logger = LogFactory.getLog(getClass());

	private AtomicBoolean flag=new AtomicBoolean(false);
	
	@Override
	public void onApplicationEvent(ContextRefreshedEvent event) {
		if (!flag.compareAndSet(false, true)){
			if (logger.isDebugEnabled()) {
				logger.debug("init has finished");
			}
			return;
		}
		if (logger.isInfoEnabled()){
			logger.info("ApplicationInit.onApplicationEvent.............");
		}

	}

}